package com.ziq.zcamp.place

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ziq.base.extension.BindingViewHolder
import com.ziq.base.extension.click
import com.ziq.base.extension.createBindingViewHolder
import com.ziq.zcamp.bean.coupon.CouponCampOnline
import com.ziq.zcamp.databinding.ItemPlaceDetailCouponBinding

class CouponAdapter(val campId : Int, val list: List<CouponCampOnline>?, val source:String = "") : RecyclerView.Adapter<BindingViewHolder<ItemPlaceDetailCouponBinding>>() {
    init {
        setHasStableIds(true)
    }

    override fun getItemCount(): Int {
        return list?.size?:0
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): BindingViewHolder<ItemPlaceDetailCouponBinding> {
        return createBindingViewHolder(parent)
    }

    override fun onBindViewHolder(
        holder: BindingViewHolder<ItemPlaceDetailCouponBinding>,
        position: Int
    ) {
        val item = list?.get(position)
        holder.binding.tvName.text = "${item?.coupon_title}"
        holder.binding.root.click {
//            val url = "${H5Url.RECEIVE_COUPON.url}?source=${source}&cv=&sid=&smid=&uid=${UserManager.instance.getUid()}&camp_id=${campId}&stock_id=${item?.stock_id}"
//            WebActivity.openWebView(GlobalContextManager.appContext!!, url, "", source = source)
        }
    }
}